/**
 *    @file       aasynworkthread.cpp
 *
 *    @brief      
 *    @details
 *
 *    @version    1.0
 *    @date       02/12/2014 05:37:16 PM
 *
 *    @author     Theophilus (), wangtf418@gmail.com 
 */
#include "asynworkthread.h"
#include "toolkit.h"

asynworkthread::asynworkthread(bf_uint32_t type, bf_uint32_t size, bf_uint32_t index, const comargs *args)
	: workthread(type, size, index, args)
{

}

asynworkthread::~asynworkthread()
{

}

bf_int_t asynworkthread::init()
{
	return BF_OK;
}

bf_int_t asynworkthread::run()
{
	init_run();

	message *msg = NULL;
	while(m_runflag)
	{
		msg = m_msg_queue.get();
		if (msg)
		{
			proc_msg(msg);
			delete msg;
		}
		else
		{
			toolkit::usleep_byselect(0, 1000);
		}
	}

	uninit_run();
	return BF_OK;
}

void asynworkthread::init_run()
{
	return;
}

void asynworkthread::uninit_run()
{
	return;
}

bf_int_t asynworkthread::put_msg(message *msg)
{
	m_msg_queue.put(msg);
	return BF_OK;
}

bf_size_t asynworkthread::get_msgq_len()
{
	return m_msg_queue.size();
}



